﻿namespace Contione.RabbitMQ.Client
{
    public abstract class RpcServerBase<TRequest, TResponse> : QueueBase
        where TRequest : class, new()
        where TResponse : class, new()
    {
        private IRabbitMQClient client;
        private string rpc_queue;
        public RpcServerBase(IRabbitMQClient client, string rpc_queue)
        {
            this.client = client;
            this.rpc_queue = rpc_queue;
        }

        /// <summary>
        /// 调用方法
        /// </summary>
        public abstract TResponse Invoke(TRequest request);

        /// <summary>
        /// 
        /// </summary>
        public override void Execute()
        {
            client.RegisterRpcHandle<TRequest, TResponse>(rpc_queue, x =>
            {
                return Invoke(x);
            });
        }
    }
}
